<?php
require_once '../../../core/fcCommon.php';
require_once '../../../core/fcORM_raschada_rx.php';
require_once '../../../log/Logger.php';
Logger::configure('../../../log4php.xml');
$logger = Logger::getLogger(__FILE__);

$json = getJsonFromRequest();

$sqlStr = "select li.*,d.drug_name from raschada_rx_lot_item li ";
$sqlStr .= "left join raschada_rx_drug d on d.drug_id=li.drug_id ";
$sqlStr .= "where li.drug_lot_id='".$json['drug_lot_id']."' ";
$sqlStr .= "order by drug_lot_item_id desc ";

$conn = new Connection();
$res = $conn->query($sqlStr);
//setlocale(LC_TIME, 'fr_FR');
setlocale(LC_ALL, 'th_TH');
foreach($res as $re){
    $val = $re->get("drug_expire_datetime");
    if(empty($val)){
        $re->put('drug_expire_datetime', '-');
    }else{
        $d = new DateTime(date($re->get("drug_expire_datetime")));  
        $re->put('drug_expire_datetime',$d->format('U|d / m / Y'));
    }
    
    $d = new DateTime(date($re->get("update_datetime")));  
    $re->put('create_datetime', Thai::date_format($d, 'วันl ที่ d F พ.ศ. Y H:i:s'));
    //$logger->debug($d->format("d M Y H:i:s")." แบบไทยๆ");
}

$jsonRes = new Map();
$jsonRes->put("identifier", "drug_lot_item_id");
$jsonRes->put("items", $res);

echo $jsonRes->toJson();
?>
